import {EDITUSER,RESET_USER} from '../constant'


import storageUtils from '../../utils/storageUtils'


let initUser = []
if (sessionStorage.user) {
    initUser = JSON.parse(sessionStorage.user)
} else if (storageUtils.getUser()) {
    const user = storageUtils.getUser();
    initUser = user
}


export default function userReducer(preState = initUser, action) {
    const {type,data} = action
    switch (type) {
        case EDITUSER:
            return data
        case RESET_USER:
            return []
        default:
            return preState
    }
}